<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="${css}/pintuer.css">
    <link rel="stylesheet" href="${css}/admin.css">
    <link rel="stylesheet" href="${css}/bootstrap.css">
    <script src="${js}/jquery.js"></script>
    <script src="${js}/pintuer.js"></script>
    <script src="${js}/bootstrap.js"></script>
</head>
<body>
<form method="post" action="${root}/book/list" id="listform">
    <div class="panel admin-panel">
        <div class="panel-head"><strong class="icon-reorder"> 内容列表</strong></div>
        <div class="padding border-bottom">
            <ul class="search" style="padding-left:10px;">
                <li> <a class="button border-main icon-plus-square-o" href="${root}/adminCategoryLoadBookView">添加新书</a> </li>
                <li>搜索：</li>
                <li>价格
                    <input name="minPrice" value="${bookVo.minPrice}" class="input" style="width:60px; line-height:17px; display:inline-block"/>--<input name="maxPrice" value="${bookVo.maxPrice}" class="input" style="width:60px; line-height:17px; display:inline-block"/>
                </li>
                <li>
                    <select name="cid" class="input" style="width:200px; line-height:17px;">
                        <option <c:if test="${bookVo.cid==0}">selected</c:if> value="0">请选择类型</option>
                        <c:forEach items="${categorys}" var="c">
                            <option <c:if test="${c.cid == bookVo.cid}">selected</c:if> value="${c.cid}">${c.cname}</option>
                        </c:forEach>
                    </select>
                </li>
                <li>
                    <input type="text" placeholder="请输入搜索关键字" name="name" value="${bookVo.name}" class="input" style="width:250px; line-height:17px;display:inline-block" />
                    <input class="button border-main icon-search" type="submit" value="搜索">
                    <a href="${root}/book/list" class="button border-main icon-bar" type="submit">清除</a>
                </li>
            </ul>
        </div>

        <table class="table table-hover text-center">
            <tr>
                <th>序号</th>
                <th>书名</th>
                <th>类型</th>
                <th>封面</th>
                <th>单价</th>
                <th>库存</th>
                <th>状态</th>
                <th width="280">操作</th>
            </tr>
            <c:forEach items="${books}" var="data" varStatus="i">
                <tr>
                    <td>${i.count}</td>
                    <td>${data.title}</td>
                    <td>${data.cname}</td>
                    <td style="height: 80px;width: 60px"><img height="100%" width="100%" src="${root}/resource/images/${data.photo}"/></td>
                    <td>${data.bprice}</td>
                    <td>${data.bnum}</td>
                    <c:if test="${data.stated==0}">
                        <td class="text-blue">已上架</td>
                    </c:if>
                    <c:if test="${data.stated==1}">
                        <td class="text-warning">已下架</td>
                    </c:if>
                    <td>
                        <div class="button-group">
                            <a class="button border-main" href="${root}/book/editor?bid=${data.bid}&cid=${data.cid}&title=${data.title}&author=${data.author}&bnum=${data.bnum}&bprice=${data.bprice}&pubdate=${data.pubdate}&publisher=${data.publisher}&story=${data.story}&cname=${data.cname}">
                                <span class="icon-edit"></span> 修改
                            </a>
                            <button type="button" class="button border-blue Up" name="${data.bid}">
                                <span class="icon-trash-o"></span> 上架
                            </button>
                            <button type="button" class="button border-red Down" name="${data.bid}">
                                <span class="icon-trash-o"></span> 下架
                            </button>
                        </div>
                    </td>
                </tr>
            </c:forEach>
            <tr>
                <td colspan="7">
                    <div class="pagelist">
                        当前<span class="text-big">${pageInfo.getPageNum()}/${pageInfo.getPages()}</span>页
                        <a href="${root}/book/list?currentPage=1&minPrice=${bookVo.minPrice}&maxPrice=${bookVo.maxPrice}&cid=${bookVo.cid}&name=${bookVo.name}">首页</a>
                        <a href="${root}/book/list?currentPage=${pageInfo.getPageNum() - 1}&minPrice=${bookVo.minPrice}&maxPrice=${bookVo.maxPrice}&cid=${bookVo.cid}&name=${bookVo.name}">上一页</a>
                        <c:forEach begin="${startPage}" end="${endPage}" var="step" step="1">
                            <c:if test="${pageInfo.getPageNum()==step}">
                                <strong class="text-red">${step}</strong>
                            </c:if>
                            <c:if test="${pageInfo.getPageNum()!=step}">
                                <a href="${root}/book/list?currentPage=${step}&minPrice=${bookVo.minPrice}&maxPrice=${bookVo.maxPrice}&cid=${bookVo.cid}&name=${bookVo.name}">${step}</a>
                            </c:if>
                        </c:forEach>
                        <a href="${root}/book/list?currentPage=${pageInfo.getPageNum() + 1}&minPrice=${bookVo.minPrice}&maxPrice=${bookVo.maxPrice}&cid=${bookVo.cid}&name=${bookVo.name}">下一页</a>
                        <a href="${root}/book/list?currentPage=${pageInfo.getPages()}&minPrice=${bookVo.minPrice}&maxPrice=${bookVo.maxPrice}&cid=${bookVo.cid}&name=${bookVo.name}">尾页</a>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</form>
<script type="text/javascript">
    $(function(){
        $(".Down").click(function(){
            var id=$(this).attr("name");
            if(confirm("是否下架该书？")){
                $.ajax({
                    url:"${root}/book/down",
                    data:{"bid":id},
                    dataType:"json",
                    success:function(result){
                        if(result.code==200){
                            alert("下架成功!");
                            window.location.reload();
                        }
                    }
                })
            }else{
                return false;
            }
        });
        $(".Up").click(function(){
            var id=$(this).attr("name");
            if(confirm("是否上架该书？")){
                $.ajax({
                    url:"${root}/book/up",
                    data:{"bid":id},
                    dataType:"json",
                    success:function(result){
                        if(result.code==200){
                            alert("上架成功!");
                            window.location.reload();
                        }
                    }
                })
            }else{
                return false;
            }
        });
    });
</script>
</body>
</html>
